package com.echo.im.mq.config;

import com.echo.im.mq.contant.QueueConstants;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.Binding;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * RabbitMQ 配置类
 * @author echo
 * @date 2024-08-15
 */
@Configuration
public class IMStarterRabbitMqConfig {


    @Bean
    public DirectExchange echoExchange() {
        return ExchangeBuilder
                .directExchange(QueueConstants.ECHO_EXCHANGE)
                .durable(true)
                .build();
    }


    @Bean
    public Queue storePrivateQueue() {
        return new Queue(QueueConstants.STORE_PRIVATE_QUEUE);
    }

    @Bean
    public Queue storeGroupQueue() {
        return new Queue(QueueConstants.STORE_GROUP_QUEUE);
    }

    @Bean
    public Queue storeSystemQueue() {
        return new Queue(QueueConstants.STORE_SYSTEM_QUEUE);
    }

    @Bean
    public Queue offlinePrivateQueue() {
        return new Queue(QueueConstants.OFFLINE_PRIVATE_QUEUE);
    }

    @Bean
    public Queue offlineSystemQueue() {
        return new Queue(QueueConstants.OFFLINE_SYSTEM_QUEUE);
    }

    @Bean
    Binding storePrivateBinding(DirectExchange echoExchange, Queue storePrivateQueue) {
        return BindingBuilder
                .bind(storePrivateQueue)
                .to(echoExchange)
                .with(QueueConstants.PUSH_SYSTEM_TOPIC);
    }

    @Bean
    Binding groupStoreBinding(DirectExchange echoExchange, Queue storeGroupQueue) {
        return BindingBuilder
                .bind(storeGroupQueue)
                .to(echoExchange)
                .with(QueueConstants.STORE_GROUP_TOPIC);
    }

    @Bean
    Binding systemStoreBinding(DirectExchange echoExchange, Queue storeSystemQueue) {
        return BindingBuilder
                .bind(storeSystemQueue)
                .to(echoExchange)
                .with(QueueConstants.STORE_SYSTEM_TOPIC);
    }

    @Bean
    Binding privateOfflineBinding(DirectExchange echoExchange, Queue offlinePrivateQueue) {
        return BindingBuilder
                .bind(offlinePrivateQueue)
                .to(echoExchange)
                .with(QueueConstants.OFFLINE_PRIVATE_TOPIC);
    }

    @Bean
    Binding systemOfflineBinding(DirectExchange echoExchange, Queue offlineSystemQueue) {
        return BindingBuilder
                .bind(offlineSystemQueue)
                .to(echoExchange)
                .with(QueueConstants.OFFLINE_SYSTEM_TOPIC);
    }

}
